package com.lx.yygh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lx.yygh.common.result.Result;
import com.lx.yygh.model.user.Patient;
import com.lx.yygh.model.user.UserInfo;
import com.lx.yygh.service.PatientService;
import com.lx.yygh.service.UserInfoService;
import com.lx.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author c先生
 * @date 2022年10月26日 上午 11:23:42
 * @describe
 */
@Api(tags = "用户管理模块（管理员端）")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;
    @Autowired
    PatientService patientService;

    @ApiOperation(value = "分页获取用户列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page")Integer page,
                              @PathVariable("limit")Integer limit,
                              UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParm = new Page<>();
        pageParm.setCurrent(page);
        pageParm.setSize(limit);
        IPage<UserInfo> userInfoPage = userInfoService.getPageList(pageParm,userInfoQueryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "锁定/解锁用户")
    @GetMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable("id")Long id,@PathVariable("status")Integer status){
        Boolean b = userInfoService.lock(id,status);
        if(b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "根据id查询用户详细信息以及就诊人信息")
    @GetMapping("/show/{id}")
    public Result show(@PathVariable("id")Long id){
        HashMap<String, Object> map = new HashMap<>();
        //查询用户信息
        UserInfo userInfo = userInfoService.findUserInfoById(id);
        map.put("userInfo",userInfo);
        //查询此用户下的所有就诊人信息
        List<Patient> patientList = patientService.findAll(id);
        map.put("patientList",patientList);
        return Result.ok(map);
    }

    @ApiOperation(value = "认证审批")
    @GetMapping("/approval/{id}/{authStatus}")
    public Result approval(@PathVariable("id")Long id,@PathVariable("authStatus")Integer authStatus){
        Boolean b = userInfoService.updateAuthstatusById(id,authStatus);
        if(b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }
}
















